<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item :label="$t('编码')">
              <a-input :placeholder="$t('请输入设备编码')" v-model="queryParam.deviceId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item :label="$t('名称')">
              <a-input :placeholder="$t('请输入设备名称')" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('管理状态')">
                <j-dict-select-tag
                  :placeholder="$t('请选择管理状态')"
                  v-model="queryParam.state"
                  dictCode="bis_device_info.state"
                />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('备注')">
                <a-input :placeholder="$t('请输入备注')" v-model="queryParam.comment"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24" v-if="!tenantId">
              <a-form-item :label="$t('门店')">
                <a-input :placeholder="$t('请输入门店编码/名称')" v-model="queryParam.shopInfo"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{ $t('查询') }}</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{
                $t('重置')
              }}</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? $t('收起') : $t('展开') }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" :loading="exloading" @click="handleExportXls($t('设备信息'))" v-has="'BisDeviceInfoController:export'">{{
        $t('导出')
      }}</a-button>
      <a-button type="primary" @click="searchQuery">{{ $t('刷新') }}</a-button>
      <a-button type="primary" v-has="'BisDeviceInfoController:edit'" @click="securitySettings">{{ $t('安全设置') }}</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">{{ $t('无图片') }}</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">{{ $t('无文件') }}</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            {{ $t('下载') }}
          </a-button>
        </template>
        <span slot="action" slot-scope="text, record">
          <a v-if="record.type == 'T10P'" @click="handleDevice(record)">{{ $t('设备码') }}</a>
          <a v-has="'BisDeviceInfoController:edit'" @click="handleEdit(record)" style="margin-left: 7px">{{ $t('编辑') }}</a>
          <a-popconfirm v-has="'BisDeviceInfoController:delete'" :title="$t('确定删除吗?')" @confirm="() => handleDelete(record.id)">
            <a style="margin-left: 7px">{{ $t('删除') }}</a>
          </a-popconfirm>
        </span>
      </a-table>
    </div>
    <device-info-modal ref="modalForm" @ok="modalFormOk"></device-info-modal>
    <security-settings-modal ref="securitySet" />
    <a-modal
      class="modal_title"
      :title="$t('设备码')"
      :visible="qrVisible"
      @cancel="handleCancel"
      :cancel-text="$t('关闭')"
    >
      <qrcode-model v-if="qrVisible" :info="info" :param="'deviceId'" :paramValue="'id'"></qrcode-model>
      <template slot="footer">
        <a-button type="default" @click="handleCancel">{{ $t('关闭') }}</a-button>
      </template>
    </a-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import DeviceInfoModal from './modules/DeviceInfoModal'
import QrcodeModel from './modules/QrcodeModel'
import SecuritySettingsModal from './modules/SecuritySettingsModal'
import Vue from 'vue'

export default {
  name: 'BarManage',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    DeviceInfoModal,
    QrcodeModel,
    SecuritySettingsModal
  },
  data() {
    return {
      description: '吧台信息管理页面',
      // 表头
      columns: [
        {
          title: this.$t('门店编码'),
          align: 'center',
          sorter: true,
          dataIndex: 'tenantId',
        },
        {
          title: this.$t('门店名称'),
          align: 'center',
          dataIndex: 'tenantId_dictText',
        },
        {
          title: this.$t('编码'),
          align: 'center',
          dataIndex: 'deviceId',
        },
        {
          title: this.$t('名称'),
          align: 'center',
          sorter: true,
          dataIndex: 'name',
        },
        {
          title: this.$t('设备类型'),
          align: 'center',
          sorter: true,
          dataIndex: 'type_dictText',
        },
        {
          title: this.$t('设备型号'),
          align: 'center',
          sorter: true,
          dataIndex: 'type',
        },
        {
          title: this.$t('管理状态'),
          align: 'center',
          sorter: true,
          dataIndex: 'state_dictText',
        },
        {
          title: this.$t('商品仓库'),
          align: 'center',
          dataIndex: 'store_dictText',
        },
        {
          title: this.$t('实币仓库'),
          align: 'center',
          dataIndex: 'currencyStore_dictText',
        },
        {
          title: this.$t('币报警值'),
          align: 'center',
          dataIndex: 'coinAlert',
        },
        {
          title: this.$t('最后更新时间'),
          align: 'center',
          sorter: true,
          dataIndex: 'updateTime',
        },
        {
          title: this.$t('局域网IP'),
          align: 'center',
          dataIndex: 'ip',
        },
        {
          title: this.$t('软件版本'),
          align: 'center',
          sorter: true,
          dataIndex: 'softVersion',
        },
        {
          title: this.$t('硬件版本'),
          align: 'center',
          sorter: true,
          dataIndex: 'hardVersion',
        },
        {
          title: this.$t('备注'),
          align: 'center',
          dataIndex: 'comment',
        },
        {
          title: this.$t('操作'),
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/device/bisDeviceInfo/list',
        delete: '/device/bisDeviceInfo/delete',
        deleteBatch: '/device/bisDeviceInfo/deleteBatch',
        exportXlsUrl: '/device/bisDeviceInfo/exportXls',
        importExcelUrl: 'device/bisDeviceInfo/importExcel',
      },
      dictOptions: {},
      qrVisible: false,
      info: {},
      gameList: [],
      selectedRowKeys: [],
      selectionRows: [],
      batchList: [],
      tenantId: Vue.ls.get('TENANT_ID'),
      queryParam: {
        type: 'EF000000',
        kind: 0,
      },
    }
  },
  created() {
    if (this.tenantId) {
      this.columns = this.columns.filter((o) => {
        return o.dataIndex != 'tenantId' && o.dataIndex != 'tenantId_dictText'
      })
    }
    this.$set(this.dictOptions, 'currencyManage', [
      { text: this.$t('是'), value: 'Y' },
      { text: this.$t('否'), value: 'N' },
    ])
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    securitySettings(){
      this.$refs.securitySet.show()
    },
    initDictConfig() {
    },
    modalFormOk() {
      this.searchQuery()
    },
    handleDevice(record) {
      this.qrVisible = true
      this.info = record
    },
    handleCancel() {
      this.qrVisible = false
    },
    onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectionRows = selectionRows
      this.batchList = []
      selectionRows.forEach((row) => {
        this.batchList.push(row.id)
      })
    },
    onClearSelected() {
      this.selectedRowKeys = []
      this.selectionRows = []
    },
    searchReset() {
      this.queryParam = {
        type: 'EF000000',
        kind: 0,
      }
      this.searchQuery(1)
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>